<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>PDF预览</title>
		<script type="text/javascript" src="js/jQuery/jquery-2.1.1.min.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="widget/layer/layer.js"></script>
		<style type="text/css">
	    	fieldset {
	    		border: 1px solid #eee;
	    	}
	    	hr {
	    		border-bottom: 1px dashed #eee;
	    		border-top: 0;
	    		border-right: 0;
	    		border-left: 0;
	    		height: 0;
	    		margin-bottom: 30px;
	    	}
	    	.part-line {
	    		border: 1px solid #eee;
	    		margin-top: 30px;
	    		margin-bottom: 30px;
	    		padding: 5px;
	    		color: red;
	    	}
	    	.showPdf {
	    		border: 1px solid #eee;
	    		margin-top: 30px;
	    		margin-bottom: 30px;
	    		padding: 5px;
	    	}
	    </style>
	    
	</head>
	
	<body>
		<fieldset>
			<legend>PDF 预览</legend>
		     <table>
		     	<tbody>
		     		<tr>
		     			<th>通行证ID：</th>
		     			<td><input id="passportId" name="passportId" placeholder="请输入【通行证ID】" /></td>
		     		</tr>
		     		<tr>
		     			<th>订单号：</th>
		     			<td><input id="orderCode" name="orderCode" style="width: 300px;" placeholder="请输入订单号" /></td>
		     		</tr>
		     		<tr>
		     			<td colspan="2">
		     				<input type="button" id="searchPdf_button" value="查询" />
		     			</td>
		     		</tr>
		     	</tbody>
		     </table>
		</fieldset>
		
		<div id="showPdf_div" class="showPdf">
			PDF 链接
	    </div>
	    
	    <hr />
	    
	    <fieldset>
			<legend>PDF 制作</legend>
		     <table>
		     	<tbody>
		     		<tr>
		     			<th>订单号：</th>
		     			<td><input id="orderCode2" name="orderCode" style="width: 300px;" placeholder="请输入订单号" /></td>
		     		</tr>
		     		<tr>
		     			<td colspan="2">
		     				<input type="button" id="createPdf_button" value="制作" />
		     			</td>
		     		</tr>
		     	</tbody>
		     </table>
		</fieldset>
	</body>
	<script type="text/javascript">
		var basePath = 'http://test2.artup.com/artup-mobile/';
		
	    $('#searchPdf_button').click(function(){
	    	// layer.msg('登录中...');
	    	
	    	var passportId = $('#passportId').val();
	    	var orderCode = $('#orderCode').val();
	    	
	    	if(isEmpty(passportId)) {
	    		// alert('请输入【通行证ID】!');
	    		layer.msg('请输入【通行证ID】!', { time: 2000, icon: 5 });
	    		
	    		return;
	    	}  else if(isEmpty(orderCode)){
	    		// alert('请输入【订单号】!');
	    		layer.msg('请输入【订单号】！', { time: 2000, icon: 5 });
	    		
	    		return;
	    	} 
	    	
	    	$(this).attr('disabled', true);
	    	
	    	$.ajax({
//	    		url : basePath + 'pdf/queryPdfPathes',
	    		url : 'pdf/queryPdfPathes',
	    		type : "get",
	    		dataType : "json",
//	    		data : $('#login_form').serialize(),
	    		data : { 'passportId' : passportId, 'orderCode' : orderCode },
	    		cache : false,
	    		async : true,	// 异步
	    		success : function(data, textStatus, jqXHR) {
	    			if ('success' == textStatus) {
	    				if(1 != data.status) {
//	    					icon: 5 哭泣，icon: 6 笑脸
	    					layer.msg(data.message, { time: 2000, icon: 5 });
	    					
	    					return;
	    				}

	    				$('#searchPdf_button').attr('disabled', false);
	    				var result = data.data;
	    				if(isNotEmpty(result)) {
	    					$('#showPdf_div').html('');		// 清空
	    					
	    					var links_a = '';
	    					$.each(result, function(index, link){
	    						var lastDiagonalLineIndex = link.lastIndexOf('/');
	    						
			    				links_a += '<a href="' + link + '" target="_blank">' + link.substring(lastDiagonalLineIndex + 1, link.length) + '</a><br /><br />';
	    					});
	
	    					$('#showPdf_div').html(links_a);
	    				}
	    			}
	    		},
	    		error : function(XMLHttpRequest, textStatus, errorThrown) {
//	    			layer.msg("textStatus = " + textStatus + ", XMLHttpRequest.status = " + XMLHttpRequest.status + ", XMLHttpRequest.readyState = " + XMLHttpRequest.readyState);
	    		}
	    	});
	    });

	    $('#createPdf_button').click(function(){
	    	var orderCode = $('#orderCode2').val();
	    	
	    	if(isEmpty(orderCode)){
	    		layer.msg('请输入【订单号】！', { time: 2000, icon: 5 });
	    		
	    		return;
	    	} 
	    	
	    	$(this).attr('disabled', true);
	    	
	    	$.ajax({
	    		url : 'pdf/createPdf',
	    		type : "get",
	    		dataType : "json",
	    		data : { 'orderCode' : orderCode },
	    		cache : false,
	    		async : true,	// 异步
	    		success : function(data, textStatus, jqXHR) {
	    			if ('success' == textStatus) {
	    				if(1 != data.status) {
//	    					icon: 5 哭泣，icon: 6 笑脸
	    					layer.msg(data.message, { time: 2000, icon: 5 });
	    					
	    					return;
	    				}

	    				$('#createPdf_button').attr('disabled', false);
    					layer.msg(data.message);
	    			}
	    		},
	    		error : function(XMLHttpRequest, textStatus, errorThrown) {
//	    			layer.msg("textStatus = " + textStatus + ", XMLHttpRequest.status = " + XMLHttpRequest.status + ", XMLHttpRequest.readyState = " + XMLHttpRequest.readyState);
	    		}
	    	});
	    });
    </script>
</html>